pub fn convert_base(num_str: &str, to_base: u32) -> String {
    // TODO: 这里写逻辑
    // 1. 先 将输入数字转换成10进制，
    // 2. 再将 10 进制数字转换成 所需进制的数字

    // 分割输入字符串
    // let input_list = num_str.split(",").map(|x|x.trim()).collect::<Vec<_>>();
    let input_number_list = num_str.split("(")
                                            .map(|x| x.trim_end_matches(")"))
                                            .collect::<Vec<_>>();
    let input_number = input_number_list[0];
    let input_number_base = input_number_list[1];

    // 将输入的源进制数字转换成10进制数字
    let base_10 = convert_to_decimal(input_number, 
        input_number_base.parse::<u32>().unwrap());
    // println!("10进制={}",base_10);

    // 从10进制转换成目标进制，并以字符串形式返回结果
    let res = convert_to_any(base_10, to_base);

    // println!("结果：{}进制={}",to_base,res);
    res.to_lowercase()
}

const BASE_STR:[&str;16] = ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"];

fn convert_to_decimal(num: &str, from_base: u32) -> u32 {
    let (mut sum,_x) = (0,0);
    for (i,char) in num.chars().rev().enumerate(){
        // println!("{}: {}",i, char);
        // index is what we need, index multiples baes.pow()
        sum += get_index(BASE_STR,&char.to_string().to_uppercase()) as u32 * from_base.pow(i as u32);
    }
    sum

}
fn get_index(nums: [&str;16], target: &str) -> i32 {
    nums.iter()
        .position(|&n| n == target) // -> Option<usize>
        .map(|i| i.try_into().unwrap()) // -> Option<i32>
        .unwrap_or(-1) // -> i32
}

fn convert_to_any(nums: u32, base: u32) ->String {
    if nums < base{
        BASE_STR[nums as usize].to_string()
    }else{
        convert_to_any(nums/base, base) + BASE_STR[(nums%base) as usize]
    }
}